/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {TreeNode} subRoot
 * @return {boolean}
 */
 var isSubtree = function(root, subRoot) {
    function digui(root){
        if(!root){
            return false;
        }
        return digui(root.left) || digui(root.right) || isSameTree(root,subRoot);
    }
    function isSameTree(p, q) {
        if(!p && !q){
            return true;
        }
        else if(p && q){
            if(p.val!=q.val){
                return false;
            }
            return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
        }
        else{
            return false;
        }
    };
    return digui(root);
};